/* 
 * File:   MyBatchUnit.h
 * Author: Morpheus
 *
 * Created on 20 juin 2013, 16:15
 */

#ifndef MYBATCHUNIT_H
#define	MYBATCHUNIT_H

#include <QtCore/qstring.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qfileinfo.h>

class QTextDocument;
class QDataStream;

class MyBatchUnitData : public QSharedData {
public:
    MyBatchUnitData();
    MyBatchUnitData(const MyBatchUnitData& orig);
    virtual ~MyBatchUnitData();
    
    QString getFilePath() const;
    bool isFile() const;
    QFileInfo getFileInfo() const;
    void setFilePath(const QString& filePath);

    void setUUID(const QString&);
    QString getUUID() const;
    
    QString getContentText() const;
    QString getContentHtml() const;
    void setContentText(const QString& patern);
    void setContentHtml(const QString& patern);
    
    QTextDocument* document() const;
    
    void save();
    bool isModified() const;
    
private:
    QString m_uuid;
    QString m_filePath;
    QString m_patern;
//    QPointer<QTextDocument> m_document;
    mutable QTextDocument* m_document;
};

class MyBatchUnit {
public:
    MyBatchUnit();
    MyBatchUnit(const MyBatchUnit& orig);
    virtual ~MyBatchUnit();
    void detach();
    
    bool isFile() const;
    QFileInfo getFileInfo() const;
    
    QString getFilePath() const;
    void setFilePath(const QString& filePath);

    void setUUID(const QString&);
    QString getUUID() const;
    
    QString getContentText() const;
    void setContentText(const QString& patern);
    
    QTextDocument* document() const;
    
    void save();
    bool isModified() const;
    
    bool operator==(const MyBatchUnit& );
    
    static const int version;
    
protected:
    QExplicitlySharedDataPointer<MyBatchUnitData> d;
    
    friend QDataStream& operator<<(QDataStream& , const MyBatchUnit&);
    friend QDataStream& operator>>(QDataStream& , MyBatchUnit&);
};

QDataStream& operator<<(QDataStream& , const MyBatchUnit&);
QDataStream& operator>>(QDataStream& , MyBatchUnit&);

#endif	/* MYBATCHUNIT_H */

